package com.hzlx.plans.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.plans.domain.MaintenancePlans;
import com.hzlx.plans.service.IMaintenancePlansService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备保养计划Controller
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/equipment")
public class MaintenancePlansController extends BaseController
{
    @Autowired
    private IMaintenancePlansService maintenancePlansService;

    /**
     * 查询设备保养计划列表
     */
    @RequiresPermissions("equipment-service:plans:list")
    @GetMapping("/plans/list")
    public TableDataInfo list(MaintenancePlans maintenancePlans)
    {
        startPage();
        List<MaintenancePlans> list = maintenancePlansService.selectMaintenancePlansList(maintenancePlans);
        return getDataTable(list);
    }

    /**
     * 导出设备保养计划列表
     */
    @RequiresPermissions("equipment-service:plans:export")
    @Log(title = "设备保养计划", businessType = BusinessType.EXPORT)
    @PostMapping("/plans/export")
    public void export(HttpServletResponse response, MaintenancePlans maintenancePlans)
    {
        List<MaintenancePlans> list = maintenancePlansService.selectMaintenancePlansList(maintenancePlans);
        ExcelUtil<MaintenancePlans> util = new ExcelUtil<MaintenancePlans>(MaintenancePlans.class);
        util.exportExcel(response, list, "设备保养计划数据");
    }

    /**
     * 获取设备保养计划详细信息
     */
    @RequiresPermissions("equipment-service:plans:query")
    @GetMapping(value = "/plans/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Integer planId)
    {
        return success(maintenancePlansService.selectMaintenancePlansByPlanId(planId));
    }

    /**
     * 新增设备保养计划
     */
    @RequiresPermissions("equipment-service:plans:add")
    @Log(title = "设备保养计划", businessType = BusinessType.INSERT)
    @PostMapping("/plans")
    public AjaxResult add(@RequestBody MaintenancePlans maintenancePlans)
    {
        return toAjax(maintenancePlansService.insertMaintenancePlans(maintenancePlans));
    }

    /**
     * 修改设备保养计划
     */
    @RequiresPermissions("equipment-service:plans:edit")
    @Log(title = "设备保养计划", businessType = BusinessType.UPDATE)
    @PutMapping("/plans")
    public AjaxResult edit(@RequestBody MaintenancePlans maintenancePlans)
    {
        return toAjax(maintenancePlansService.updateMaintenancePlans(maintenancePlans));
    }

    /**
     * 删除设备保养计划
     */
    @RequiresPermissions("equipment-service:plans:remove")
    @Log(title = "设备保养计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/plans/{planIds}")
    public AjaxResult remove(@PathVariable Integer[] planIds)
    {
        return toAjax(maintenancePlansService.deleteMaintenancePlansByPlanIds(planIds));
    }
}
